/**
 * DataBaseDocumentBuilder.java	1.0 2007 六月 6 11:35:41,创建
 */

package org.in4j.search.index.sandbox;

import java.sql.ResultSet;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;

/**
 *
 * @author 杨帆
 * @version 1.0 2007 六月 6 11:35:41,创建
 */
public class DataBaseDocumentBuilder implements DocumentBuilder
{
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(DataBaseDocumentBuilder.class);
	private final ResultSet rs;
	private final DocumentMetaData meta;

	public DataBaseDocumentBuilder(ResultSet rs,DocumentMetaData meta)
	{
		this.rs = rs;
		this.meta = meta;
	}

	public Document buildDocument()
	{
		Document doc = new Document();
		doc.setBoost(meta.getBoost());
		for(FieldMetaData fieldMeta : meta.getFieldMetaDataList())
		{
			Field field = buildField(rs,fieldMeta);
			doc.add(field);
		}
		return doc;
	}

	private Field buildField(ResultSet rs, FieldMetaData fieldMeta)
	{
		FieldBuilder fieldBuilder = new DataBaseFieldBuilder(rs,fieldMeta);
		Field field = fieldBuilder.buildField();
		return field;
	}

}
